/*
* pps_bom
*/
package com.pitop.assembly.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.assembly.entity.AssemblyMaterial;
import com.pitop.assembly.service.AssemblyMaterialSV;

/**
 * 构成组件的物料 控制器
 *
 * @author berton
 */
@RestController
@RequestMapping("/assemblyMaterial")
@Slf4j
@Api(value = "构成组件的物料控制器", description = "构成组件的物料控制器")
public class AssemblyMaterialCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private AssemblyMaterialSV assemblyMaterialSV;

    /**
     * 查询AssemblyMaterial一个详情信息
     *
     * @param id
     * @param assemblyCode 组件编码
     * @param materialCode 物料编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyMaterial一个详情信息", notes = "查询AssemblyMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "assemblyCode", value = "组件编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public AssemblyMaterial load(Long id, String assemblyCode, String materialCode) {
        if (id == null) {
            return null;
        }
        if (assemblyCode == null) {
            return null;
        }
        if (materialCode == null) {
            return null;
        }
        AssemblyMaterial assemblyMaterial = assemblyMaterialSV.load(id, assemblyCode, materialCode);
        log.info(JSON.toJSONString(assemblyMaterial));
        return assemblyMaterial;
    }

    /**
     * 查询AssemblyMaterial一个详情信息，(将查询关联数据)
     *
     * @param id
     * @param assemblyCode 组件编码
     * @param materialCode 物料编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyMaterial一个详情信息", notes = "查询AssemblyMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "assemblyCode", value = "组件编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/get")
    @ResponseBody
    public AssemblyMaterial get(Long id, String assemblyCode, String materialCode) {
        if (id == null) {
            return null;
        }
        if (assemblyCode == null) {
            return null;
        }
        if (materialCode == null) {
            return null;
        }
        AssemblyMaterial assemblyMaterial = assemblyMaterialSV.get(id, assemblyCode, materialCode);
        log.info(JSON.toJSONString(assemblyMaterial));
        return assemblyMaterial;
    }

    /**
     * 根据条件id查询AssemblyMaterial一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyMaterial一个详情信息", notes = "查询AssemblyMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public AssemblyMaterial loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        AssemblyMaterial assemblyMaterial = assemblyMaterialSV.loadById(id);
        log.info(JSON.toJSONString(assemblyMaterial));
        return assemblyMaterial;
    }

    /**
     * 根据条件assemblyCode查询AssemblyMaterial一个详情信息
     *
     * @param assemblyCode 组件编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyMaterial一个详情信息", notes = "查询AssemblyMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "assemblyCode", value = "组件编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/assemblyCode/{assemblyCode}")
    @ResponseBody
    public AssemblyMaterial loadByAssemblyCode(@PathVariable String assemblyCode) {
        if (assemblyCode == null) {
            return null;
        }
        AssemblyMaterial assemblyMaterial = assemblyMaterialSV.loadByAssemblyCode(assemblyCode);
        log.info(JSON.toJSONString(assemblyMaterial));
        return assemblyMaterial;
    }

    /**
     * 根据条件materialCode查询AssemblyMaterial一个详情信息
     *
     * @param materialCode 物料编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyMaterial一个详情信息", notes = "查询AssemblyMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "materialCode", value = "物料编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/materialCode/{materialCode}")
    @ResponseBody
    public AssemblyMaterial loadByMaterialCode(@PathVariable String materialCode) {
        if (materialCode == null) {
            return null;
        }
        AssemblyMaterial assemblyMaterial = assemblyMaterialSV.loadByMaterialCode(materialCode);
        log.info(JSON.toJSONString(assemblyMaterial));
        return assemblyMaterial;
    }

    /**
     * 根据条件id查询AssemblyMaterial一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyMaterial一个详情信息", notes = "查询AssemblyMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/get/id/{id}")
    @ResponseBody
    public AssemblyMaterial getById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        AssemblyMaterial assemblyMaterial = assemblyMaterialSV.getById(id);
        log.info(JSON.toJSONString(assemblyMaterial));
        return assemblyMaterial;
    }

    /**
     * 根据条件assemblyCode查询AssemblyMaterial一个详情信息
     *
     * @param assemblyCode 组件编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyMaterial一个详情信息", notes = "查询AssemblyMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "assemblyCode", value = "组件编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/get/assemblyCode/{assemblyCode}")
    @ResponseBody
    public AssemblyMaterial getByAssemblyCode(@PathVariable String assemblyCode) {
        if (assemblyCode == null) {
            return null;
        }
        AssemblyMaterial assemblyMaterial = assemblyMaterialSV.getByAssemblyCode(assemblyCode);
        log.info(JSON.toJSONString(assemblyMaterial));
        return assemblyMaterial;
    }

    /**
     * 根据条件materialCode查询AssemblyMaterial一个详情信息
     *
     * @param materialCode 物料编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询AssemblyMaterial一个详情信息", notes = "查询AssemblyMaterial一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "materialCode", value = "物料编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/get/materialCode/{materialCode}")
    @ResponseBody
    public AssemblyMaterial getByMaterialCode(@PathVariable String materialCode) {
        if (materialCode == null) {
            return null;
        }
        AssemblyMaterial assemblyMaterial = assemblyMaterialSV.getByMaterialCode(materialCode);
        log.info(JSON.toJSONString(assemblyMaterial));
        return assemblyMaterial;
    }

    /**
     * 查询AssemblyMaterial信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询AssemblyMaterial信息集合", notes = "查询AssemblyMaterial信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<AssemblyMaterial> list(@RequestBody @ApiIgnore AssemblyMaterial assemblyMaterial, Integer curPage, Integer pageSize) {
        Page<AssemblyMaterial> page = new Page<AssemblyMaterial>(pageSize, curPage);
        List<AssemblyMaterial> assemblyMaterials = assemblyMaterialSV.list(assemblyMaterial, page.genRowStart(), page.getPageSize());
        int total = assemblyMaterialSV.count(assemblyMaterial);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return assemblyMaterials;
    }

    /**
     * 查询AssemblyMaterial信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询AssemblyMaterial信息集合", notes = "查询AssemblyMaterial信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "assemblyCode", value = "组件编码", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<AssemblyMaterial> listByPk(Long id, String assemblyCode, String materialCode, Integer curPage, Integer pageSize) {
        Page<AssemblyMaterial> page = new Page<AssemblyMaterial>(pageSize, curPage);
        List<AssemblyMaterial> assemblyMaterials = assemblyMaterialSV.list(id, assemblyCode, materialCode, page.genRowStart(), page.getPageSize());
        int total = assemblyMaterialSV.count(id, assemblyCode, materialCode);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return assemblyMaterials;
    }

    /**
     * 统计AssemblyMaterial信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计AssemblyMaterial信息数量根据主键", notes = " 统计AssemblyMaterial信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "assemblyCode", value = "组件编码", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id, String assemblyCode, String materialCode) {
        return assemblyMaterialSV.count(id, assemblyCode, materialCode);
    }

    /**
     * 统计AssemblyMaterial信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计AssemblyMaterial信息数量", notes = "统计AssemblyMaterial信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "assemblyCode", value = "组件编码", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody AssemblyMaterial assemblyMaterial) {
        return assemblyMaterialSV.count(assemblyMaterial);
    }

    /**
     * 创建AssemblyMaterial
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建AssemblyMaterial", notes = "创建AssemblyMaterial")
    @ApiImplicitParams({
    })
    @PostMapping("/build")
    @ResponseBody
    public AssemblyMaterial build(@RequestBody @ApiIgnore AssemblyMaterial assemblyMaterial) {
        assemblyMaterialSV.save(assemblyMaterial);
        return assemblyMaterial;
    }

    /**
     * 修改AssemblyMaterial
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改AssemblyMaterial", notes = "修改AssemblyMaterial")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "assemblyCode", value = "组件编码", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public AssemblyMaterial modify(@RequestBody @ApiIgnore AssemblyMaterial assemblyMaterial) {
        assemblyMaterialSV.modify(assemblyMaterial);
        return assemblyMaterial;
    }

    /**
     * 删除AssemblyMaterial
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除AssemblyMaterial", notes = "删除AssemblyMaterial")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "assemblyCode", value = "组件编码", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String assemblyCode, String materialCode) {
        assemblyMaterialSV.delete(id, assemblyCode, materialCode);
        return BeanRet.create(true, "删除AssemblyMaterial成功");
    }

}
